package com.cole.gx095.controller;

import com.cole.gx095.Repository.SaleBillgoodsRepository;
import com.cole.gx095.Repository.SalebillRepository;
import com.cole.gx095.Repository.SalecontractRepository;
import com.cole.gx095.domain.CostVo;
import com.cole.gx095.domain.StockVo;
import com.cole.gx095.domain.mapper.CostVOMapper;
import com.cole.gx095.domain.mapper.StockMapper;
import com.cole.gx095.entity.Salebill;
import com.cole.gx095.entity.Salecontract;
import com.cole.gx095.entity.Stockgoods;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class stock {
    @Autowired
    SalecontractRepository salecontractRepository;
    @Autowired
    SalebillRepository salebillRepository;
    @Autowired
    SaleBillgoodsRepository saleBillgoodsRepository;
    @Test
    void text1(){
        Stockgoods stockgoods = new Stockgoods();
        StockVo stockVo = new StockVo();
        stockgoods.setContractNum("s333");
        stockgoods.setRemakes("111111");
        stockVo.setBillNum("1112");

        StockVo conver = StockMapper.INSTANCT.conver(stockgoods);
        conver.setBillType("11");
        System.out.println("conver = " + conver);
    }
    @Test
    void text2(){
        Page<Salebill> page1 = salebillRepository.findAll(PageRequest.of(1 - 1, 10));
        page1.getContent().forEach(System.out::println);
        List<CostVo> costVoList = new ArrayList<>();
        for (Salebill salebill : page1.getContent()) {
            CostVo conver = CostVOMapper.INSTANCT.conver(salebill);
            System.out.println("conver = " + conver);
            conver.setBuyUnit(salecontractRepository.findoneBycontractNum(salebill.getContractNum()).getBuyUnit());
            costVoList.add(conver);
        }
        costVoList.forEach(System.out::println);
    }
    @Test
    void text3(){
        Salebill salebill = new Salebill();
        salebill.setBillNum("123");
        salebill.setStatus(0);
        Salecontract salecontract = new Salecontract();
        salecontract.setContractNum("cont");
        salecontract.setBuyUnit("fzu");
        CostVo conver = CostVOMapper.INSTANCT.conver(salebill);
//        CostVo conv = CostVOMapper.INSTANCT.salebillcontractconver(salebill,salecontract);
        System.out.println("conver = " + conver);
//        System.out.println("conv = " + conv);
    }

    @Test
    @Transactional
    void text4(){
        Page<Salebill> page1 = salebillRepository.findAll(PageRequest.of(1 - 1, 7));
        List<CostVo> costVoList = new ArrayList<>();
        for (Salebill salebill : page1.getContent()) {
            System.out.println("salebill = " + salebill);
            CostVo conver = CostVOMapper.INSTANCT.conver(salebill);
            conver.setCreateDate(salebill.getCreateDate());
            conver.setCreateAdminTrueName(salebill.getCreateAdminTrueName());
            costVoList.add(conver);
        }
        costVoList.forEach(System.out::println);
    }
    @Test
    void test5(){
        Double a = 101.0;
        if(a > 100.0)
            System.out.println("a");
    }
}
